package cn.xingchen.xiangqin.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.xingchen.common.core.controller.BaseController;
import cn.xingchen.common.core.domain.AjaxResult;
import cn.xingchen.common.core.page.TableDataInfo;
import cn.xingchen.common.enums.BusinessType;
import cn.xingchen.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.xingchen.common.annotation.Log;
import cn.xingchen.xiangqin.domain.OnWall;
import cn.xingchen.xiangqin.service.IOnWallService;

/**
 * 上墙Controller
 * 
 * @author 爱喝茶的耀哥
 * @date 2023-05-20
 */
@RestController
@RequestMapping("/xiangqin/wall")
public class OnWallController extends BaseController
{
    @Autowired
    private IOnWallService onWallService;

    /**
     * 查询上墙列表
     */
    @PreAuthorize("@ss.hasPermi('xiangqin:wall:list')")
    @GetMapping("/list")
    public TableDataInfo list(OnWall onWall)
    {
        startPage();
        List<OnWall> list = onWallService.selectOnWallList(onWall);
        return getDataTable(list);
    }

    /**
     * 导出上墙列表
     */
    @PreAuthorize("@ss.hasPermi('xiangqin:wall:export')")
    @Log(title = "上墙", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OnWall onWall)
    {
        List<OnWall> list = onWallService.selectOnWallList(onWall);
        ExcelUtil<OnWall> util = new ExcelUtil<OnWall>(OnWall.class);
        util.exportExcel(response, list, "上墙数据");
    }

    /**
     * 获取上墙详细信息
     */
    @PreAuthorize("@ss.hasPermi('xiangqin:wall:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(onWallService.selectOnWallById(id));
    }

    /**
     * 新增上墙
     */
    @PreAuthorize("@ss.hasPermi('xiangqin:wall:add')")
    @Log(title = "上墙", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OnWall onWall)
    {
        return toAjax(onWallService.insertOnWall(onWall));
    }

    /**
     * 修改上墙
     */
    @PreAuthorize("@ss.hasPermi('xiangqin:wall:edit')")
    @Log(title = "上墙", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OnWall onWall)
    {
        return toAjax(onWallService.updateOnWall(onWall));
    }

    /**
     * 删除上墙
     */
    @PreAuthorize("@ss.hasPermi('xiangqin:wall:remove')")
    @Log(title = "上墙", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(onWallService.deleteOnWallByIds(ids));
    }
}
